//
//  CMDBRegisterSexTF.swift
//  CMDB
//
//  Created by 王磊 on 08/05/2017.
//  Copyright © 2017 CMDB. All rights reserved.
//

import UIKit

class CMDBRegisterSexTF: CMDBRegisterTF {
    
    private var male: UIButton = UIButton(type: .Custom)
    
    private var female: UIButton = UIButton(type: .Custom)
    
}
extension CMDBRegisterSexTF {
    
    override func addOwnSubviews() {
        super.addOwnSubviews()
        
        addSubview(male)
        
        addSubview(female)
        
    }
    override func configOwnSubviews() {
        super.configOwnSubviews()
        
        female.setTitle("女", forState: .Normal)
        
        female.setTitle("女", forState: .Selected)
        
        female.titleLabel?.font = CMDB_Register_TF_FONT
        
        female.setTitleColor(CMDB_Register_TF_PlaceHolder_Color, forState: .Normal)
        
        female.setTitleColor(UIColor.Hex6(0xff6d00, alpha: 54), forState: .Selected)
        
        female.setImage(UIImage(named: "user_reg_female_0"), forState: .Normal)
        
        female.setImage(UIImage(named: "user_reg_female_1"), forState: .Selected)
        
        female.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -3)
        
        male.setImage(UIImage(named: "user_reg_male_0"), forState: .Normal)
        
        male.setImage(UIImage(named: "user_reg_male_1"), forState: .Selected)
        
        male.setTitle("男", forState: .Normal)
        
        male.setTitle("男", forState: .Selected)
        
        male.titleLabel?.font = CMDB_Register_TF_FONT
        
        male.setTitleColor(CMDB_Register_TF_PlaceHolder_Color, forState: .Normal)
        
        male.setTitleColor(UIColor.Hex6(0xff6d00, alpha: 54), forState: .Selected)
        
        male.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -3)
        
        //        male.sizeToFit()
        
        male.selected = true
        
        male.addTarget(self, action: #selector(btnClick), forControlEvents: .TouchUpInside)
        
        female.addTarget(self, action: #selector(btnClick), forControlEvents: .TouchUpInside)
    }
}
extension CMDBRegisterSexTF {
    
    @objc private func btnClick(sender: UIButton) {
        
        if sender == male {
            
            if !male.selected {
                
                male.selected = true
                
                female.selected = false
            }
        } else {
            
            if !female.selected {
                
                female.selected = true
                
                male.selected = false
            }
        }
        
        if let target = unsureTarget {
            
            let argu = ArguInfo()
            
            argu.view = self
            
            argu.controlEvent = male.selected ? ControlEvent.Male : ControlEvent.Female
            
            TSRuntimeManager.getInstance().addTarget(target, andSel: unsureAction!, andAnyArgu: argu)
        }
        
    }
    
}

extension CMDBRegisterSexTF {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        male.snp_makeConstraints { [weak self] (make) in
            
            make.left.equalTo(self!.textWidth + 10)
            
            make.centerY.equalTo(5)
        }
        female.snp_makeConstraints { [weak self] (make) in
            
            make.left.equalTo(self!.textWidth * 2 + 10)
            
            make.centerY.equalTo(5)
        }
    }
    
}
extension CMDBRegisterSexTF {
    
}
